package com.ln.第二遍1027.demo002;

import java.lang.reflect.Field;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/10/27 17:08
 */
public class Test002 {
    public static void main(String[] args) throws Exception{
        Class<Student> studentClass = Student.class;
        Field age = studentClass.getDeclaredField("age");
        System.out.println("age = " + age);

        Field[] declaredFields = studentClass.getDeclaredFields();
        for (Field field :declaredFields){
            System.out.println("field = " + field);
        }

        Field address = studentClass.getField("address");
        System.out.println("address = " + address);

        Field[] fields = studentClass.getFields();
        for (Field field :fields){
            System.out.println("field = " + field);
        }
    }
}
class School{
    private String name;
    public String address;

}
class Student extends School {
    private String sex;
    public int age;

    @Override
    public String toString() {
        return "Student{" +
                "sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }
}
